import md5 from 'blueimp-md5';
/**
 * 加密类
 *
 * @class Encrypt
 */
class Encrypt {
  constructor(config) {
    this.securityMerchantsCode = config.securityMerchantsCode;
    this.securityMerchantsNo = config.securityMerchantsNo;
    this.securitySign = config.securitySign;
  }

  wrapWithRSA(data) {
    const {
      securitySign,
      securityMerchantsCode,
      securityMerchantsNo
    } = this;
    const dataStr = JSON.stringify(data);
    const sign = md5(dataStr + securitySign);

    return {
      merchantsNo: securityMerchantsNo,
      merchantsCode: securityMerchantsCode,
      sign,
      data: dataStr,
      timestamp: Date.parse(new Date())
    };
  }

  unWrapWithRSA(data) {
    return data;
  }
}

export default Encrypt;
